#include('header.html')
<script type="text/javascript">
    changeTab('线上公司');

    $(function () {
        $('select[name="type"]').change(function (e) {
            $('#shop-form').submit();
        });
    });

    function gotoPage(e, page) {
        var type = $('select[name="type"]').val();
        var pages = ${pages.totalPages};
        var status = $(e).parent().attr("class");
        if (page > 0 && page <= pages && page !== ${pages.number + 1} &&
            status !== "active") {
            location.href = '/admin/shopIds?pageNo=' + page + "&type=" + type;
        }
    }

    function c_delete(id, k_name) {
        var flag = confirm("确定要删除<" + k_name + ">吗？");
        if (flag) {
            $.post('/shop/delete/' + id, function (data) {
                if (data.success) {
                    alert("SUCCESS: 删除成功！");
                    location.reload();
                } else {
                    alert("ERROR: " + data.msg);
                    location.reload();
                }
            });
        }
    }

    /**
     * 刷新所有公司总评
     */
    function refresh() {
        $.post('/shop/refresh', function (data) {
            location.reload();
        });
    }

    function shop_show(shopId) {
        location.href = '/admin/count?shop_id=' + shopId;
    }

    function load_change(id) {
        var $modal = $("#shopModal");
        $modal.find(".modal-content").load("/shop/change/" + id);
        $modal.modal();
    }

    function load_add() {
        var $modal = $("#shopModal");
        $modal.find(".modal-content").load("/shop/add");
        $modal.modal();
    }
</script>

<!-- 添加公司信息模态框 -->
<div class="modal fade" id="shopModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 模态框内容动态加载 -->
        </div>
    </div>
</div>

<div class="plan-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <a class="text-black" href="/admin/shopIds">
                <h4><span class="fa fa-hand-o-right"></span> 线上公司</h4>
            </a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <form id="shop-form" method="get">
                    <div class="input-group min-min-input pull-left">
                        <select name="type" class="form-control min-min-select">
                            <option value="">-- 公司类型 --</option>
                            #for(Map.Entry et : shopTypeMap)
                            <option value="${et.key}" ${type==et.key.asInt()?'selected':''}>${et.value}</option>
                            #end
                        </select>
                    </div>
                    <button type="button" onclick="load_add();" class="btn btn-info btn-sm">添加</button>
                    #if(admin.grade > 1)
                    <button type="button" onclick="refresh();" class="btn btn-warning btn-sm">刷新总评</button>
                    #end
                </form>
            </div>
        </div>
        <div>
            <div class="col-lg-12 col-xs-12">
                <table class="table table-striped">
                    <thead class="bg-color-x">
                    <tr>
                        <td>排名</td>
                        <td>公司名</td>
                        <td>类型</td>
                        <td>联系电话</td>
                        <td>公司邮箱</td>
                        <td>公司地址</td>
                        <td>总评</td>
                        <td style="width: 180px;">操作</td>
                    </tr>
                    </thead>
                    <tbody>
                        #for(Shop s : pages.content)
                        <tr>
                            <td>${for.index}</td>
                            <td>${s.name}</td>
                            <td><span class='shop-type-${s.type}'> </span></td>
                            <td>${s.tel}</td>
                            <td>${s.email}</td>
                            <td>${s.address}</td>
                            <td><span class="label label-success">${s.total.format('0.00') ?! '0'}</span></td>
                            <td>
                                <button onclick="shop_show('${s.id}')"
                                        class="btn btn-xs btn-success">评分详情</button>
                                <button onclick="load_change('${s.id}');"
                                        class="btn btn-xs btn-primary">修改</button>
                                #if(admin.grade > 1)
                                <button onclick="c_delete('${s.id}', '${s.name}');"
                                        class="btn btn-xs btn-danger">删除</button>
                                #end
                            </td>
                        </tr>
                        #else
                        <tr>
                            <td align="center" colspan="8">
                            暂无数据 <a href="javascript:" class="text-danger"
                            onclick="load_add();">快去添加</a>
                            </td>
                        </tr>
                        #end
                    </tbody>
                </table>
                <!-- 分页按钮 -->
                #if(pages.totalPages > 1)
                <div class="col-lg-12 col-xs-12 text-center">
                    <ul style="margin: 0;" class="pagination pagination-sm">
                        <!--<li onclick="gotoPage(this, 1)"><a href="javascript:">首页</a></li>
                        #for(int i : range(1, pages.totalPages))
                        <li class="${i == pages.number + 1 ? 'active':''}"
                            onclick="gotoPage(this, ${i})"><a href="javascript:">${i}</a></li>
                        #end
                        <li onclick="gotoPage(this, ${pages.totalPages})"><a href="javascript:">尾页</a></li>-->
                    </ul>
                    <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
                            共${pages.totalPages}页，${pages.totalElements}条数据
                        </span>
                </div>
                #end
            </div>
        </div>
    </div>
</div>

#include('footer.html')